<template>
    <div id="phy-score-detail">
        <el-breadcrumb separator="/" class="common-bread">
            <el-breadcrumb-item :to="{ path: '/physicalScore' }">体测成绩</el-breadcrumb-item>
            <el-breadcrumb-item>成绩详情</el-breadcrumb-item>
            <span class="phy-standard fr" @click="checkStandard()">体测标准</span>
        </el-breadcrumb>
        <div class="score-detail contentBox">
            <div class="list_head">
                <span>成绩详情</span>
                <el-button class="list_btn" type="primary" @click="cancle">返回</el-button>
            </div>
            <div class="score-content">
                <div class="phystudent-info-head">
                    <span>基本信息</span>
                </div>
                <table class="phystudent-info">
                    <tbody>
                        <tr>
                            <td>学生姓名</td>
                            <td>{{stuInfo.name}}</td>
                            <td>性别</td>
                            <td>{{stuInfo.gender}}</td>
                        </tr>
                        <tr>
                            <td>民族</td>
                            <td>{{stuInfo.nation}}</td>
                            <td>出生日期</td>
                            <td>{{stuInfo.birthDate}}</td>
                        </tr>
                        <tr>
                            <td>学籍号</td>
                            <td>{{stuInfo.campusId}}</td>
                            <td>入学年份</td>
                            <td>{{stuInfo.enterYear}}</td>
                        </tr>
                        <tr>
                            <td>班级</td>
                            <td>{{stuInfo.className}}</td>
                            <td>年级</td>
                            <td>{{stuInfo.grade}}</td>
                        </tr>
                        <tr>
                            <td>学校</td>
                            <td>{{stuInfo.schoolName}}</td>
                        </tr>
                    </tbody>
                </table>
                <div class="phystudent-info-head">
                    <span>体测成绩</span>
                </div>
                <div v-if="hasScore" class="stu-physical-mark">
                    <div v-for="item in physicalMark" v-if="item.mark || item.score" class="mark-item">
                        <div class="mark-key">{{item.physicalName}}</div>
                        <div class="mark-value">
                            <span v-if="item.mark" :class="item.mark=='不及格'?'red':''">{{item.mark}}</span>
                            <span v-if="item.score">（{{item.score}}）</span>
                        </div>
                    </div>
                </div>
                <div v-else class="nophysicalScore">暂无成绩</div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                campusId: '',
                physicalId: '',
                hasScore: true,
                stuInfo: {},
                physicalMark: [
                    { physicalName: '身高', physicalItem: 'height', score: '', mark: '' },
                    { physicalName: '体重', physicalItem: 'weight', score: '', mark: '' },
                    { physicalName: 'BMI(体重÷身高＾2)', physicalItem: 'bmi', score: '', mark: '' },
                    { physicalName: '肺活量', physicalItem: 'vitalCapacity', score: '', mark: '' },
                    { physicalName: '50米跑', physicalItem: 'run50', score: '', mark: '' },
                    { physicalName: '立定跳远', physicalItem: 'standinglongjump', score: '', mark: '' },
                    { physicalName: '坐位体前屈', physicalItem: 'sitandreach', score: '', mark: '' },
                    { physicalName: '仰卧起坐', physicalItem: 'sitandup', score: '', mark: '' },
                    { physicalName: '引体向上', physicalItem: 'pullup', score: '', mark: '' },
                    { physicalName: '1000米跑', physicalItem: 'run1000', score: '', mark: '' },
                    { physicalName: '800米跑', physicalItem: 'run800', score: '', mark: '' },
                    { physicalName: '50*8往返跑', physicalItem: 'returnRun', score: '', mark: '' },
                    { physicalName: '一分钟跳绳', physicalItem: 'roleJump', score: '', mark: '' },
                    { physicalName: '标准分', physicalItem: 'total', score: '', mark: '' },
                    { physicalName: '附加分', physicalItem: 'extra', score: '', mark: '' },
                    { physicalName: '体测总分', physicalItem: 'computer', score: '', mark: '' },
                    { physicalName: '体测成绩', physicalItem: 'scoreLevel', score: '', mark: '' }
                ]
            }
        },
        mounted() {
            let physicalScoreInfo = JSON.parse(this.$util.getStore("physicalScoreInfo"));
            this.campusId = physicalScoreInfo.campusId;
            this.physicalId = physicalScoreInfo.physicalId;
            this.getStudentInfo();
            this.getPhysicalScoreDetail();
        },
        methods: {
            // 获取学生信息
            getStudentInfo() {
                let url = '/adminapi/v1/user/student/list';
                // let url = '/adminapi/v1/user/student/info';
                this.$axios.get(url, {
                    params: {
                        pageNum: 1,
                        pageSize: 10,
                        studentNumber: this.campusId
                    }
                }).then(response => {
                    if (response.data.error == 10000) {
                        let proObj = response.data.data.content[0]
                        if (proObj) {
                            let gradeName = this.$util.gradeFormat(proObj.grade * 1);
                            let className = gradeName + proObj.claNumber + "班";
                            this.stuInfo = {
                                name: proObj.name,
                                gender: proObj.gender == 1 ? '男' : '女',
                                nation: proObj.nation,
                                birthDate: proObj.birthday > 0 ? new Date(proObj.birthday * 1).format('yyyy.MM.dd') : '',
                                campusId: proObj.studentNumber,
                                enterYear: proObj.enrollmentYear > 0 ? new Date(proObj.enrollmentYear * 1).format('yyyy') + '年' : '',
                                grade: this.$util.gradeFormat(proObj.grade),  // 年级
                                className: className,
                                schoolName: proObj.schoolName,
                                teacherName: proObj.teacherName,
                            }
                        }
                    }
                })
            },
            // 获取成绩详情
            getPhysicalScoreDetail() {

                this.$axios.post('/jlp/physical/score/serach/oneperson', {
                    studentCode: this.campusId,
                    physicalId: this.physicalId * 1
                }).then(res => {
                    if (res.data.error == 10000) {
                        let proObj = res.data.data;
                        if (proObj) {
                            if (proObj.allEmpty == 1) {
                                // 暂无成绩return
                                return this.hasScore = false
                            } else {
                                this.hasScore = true
                            }
                            let prebmi = '', computerTotal = '';
                            if (proObj.run1000 == -100000) {
                                proObj.run1000 = ''
                            } else if (proObj.run1000 == -99999) {
                                proObj.run1000 = '未测'
                            } else {
                                proObj.run1000 = Math.floor(proObj.run1000 / 1000 / 60) + ' 分 ' + (proObj.run1000 / 1000) % 60 + ' 秒'
                            }

                            if (proObj.run800 == -100000) {
                                proObj.run800 = ''
                            } else if (proObj.run800 == -99999) {
                                proObj.run800 = '未测'
                            } else {
                                proObj.run800 = Math.floor(proObj.run800 / 1000 / 60) + ' 分 ' + (proObj.run800 / 1000) % 60 + ' 秒'
                            }

                            if (proObj.height == -100000) {
                                prebmi = '';
                            } else if (proObj.height == -99999) {
                                prebmi = '未测'
                            } else {
                                prebmi = ((proObj.weight / 1000) / ((proObj.height / 1000) * (proObj.height / 1000))).toFixed(2)
                            }

                            switch (proObj.scoreLevel) {
                                case 1:
                                    proObj.scoreLevel = '优秀'
                                    break;
                                case 2:
                                    proObj.scoreLevel = '良好'
                                    break;
                                case 3:
                                    proObj.scoreLevel = '及格'
                                    break;
                                case 4:
                                    proObj.scoreLevel = '不及格'
                                    break;
                                case -99999:
                                    proObj.scoreLevel = '未完成'
                                    break;
                            }
                            if (proObj.totalScore == -99999 || proObj.totalScore == -100000) {
                                computerTotal = '-99999'
                            } else {
                                computerTotal = (proObj.totalScore + proObj.extraScore) / 100 + '分'
                            }

                            let phyObj = {
                                height: proObj.height / 10 + '厘米',
                                weight: (proObj.weight / 1000) + '千克',
                                bmi: prebmi,
                                bmiScore: proObj.bmiScore / 100 + '分',
                                vitalCapacity: proObj.vitalCapacity + ' 毫升',
                                vitalCapacityScore: proObj.vitalCapacityScore / 100 + '分',
                                run50: proObj.run50 / 1000 + ' 秒',
                                run50Score: proObj.run50Score / 100 + '分',
                                standinglongjump: proObj.standinglongjump / 10 + ' 厘米',
                                standinglongjumpScore: proObj.standinglongjumpScore / 100 + '分',
                                sitandreach: proObj.sitandreach / 10 + ' 厘米',
                                sitandreachScore: proObj.sitandreachScore / 100 + '分',
                                sitandup: proObj.sitandup + ' 个',
                                sitandupScore: proObj.sitandupScore / 100 + '分',
                                pullup: proObj.pullup + ' 个',
                                pullupScore: proObj.pullupScore / 100 + '分',
                                run1000: proObj.run1000,
                                run1000Score: proObj.run1000Score / 100 + '分',
                                run800: proObj.run800,
                                run800Score: proObj.run800Score / 100 + '分',
                                returnRun: proObj.returnRun / 1000 + ' 秒',
                                returnRunScore: proObj.returnRunScore / 100 + '分',
                                roleJump: proObj.roleJump + ' 个',
                                roleJumpScore: proObj.roleJumpScore / 100 + '分',
                                extraScore: proObj.extraScore / 100 + '分',
                                totalScore: proObj.totalScore / 100 + '分',
                                computerScore: computerTotal,
                                scoreLevel: proObj.scoreLevel
                            }
                            this.physicalScoreFormat(this.physicalMark, phyObj)
                        } else {
                            this.hasScore = false
                        }
                    } else {
                        this.hasScore = false
                    }
                }).catch(() => {
                    this.hasScore = false
                })
            },

            // 体测标准
            checkStandard() {
                location.href = '/#/physicalStandard'
            },

            cancle() {
                this.$util.refreshTo("/#/physicalScore");
            },

            // 成绩整理
            physicalScoreFormat(phyArr, phyObj) {
                phyArr.forEach(element => {
                    for (let i in phyObj) {
                        if (i == element.physicalItem) {
                            if (phyObj[i].indexOf('-100') > -1) {
                                element.mark = ''
                            } else if (phyObj[i].indexOf('-99') > -1) {
                                element.mark = '未测'
                            } else {
                                element.mark = phyObj[i]
                            }
                        }

                        if (i == element.physicalItem + 'Score') {
                            if (phyObj[i].indexOf('-100') > -1) {
                                element.score = ''
                            } else if (phyObj[i].indexOf('-99') > -1) {
                                element.score = ''
                            } else {
                                element.score = phyObj[i]
                            }
                        }
                    }
                });
                return phyArr;
            },
        }
    }
</script>
<style scoped>
    .score-detail {
        padding-top: 1px;
        background-color: #ffffff;
    }

    .phystudent-info-head {
        line-height: 56px;
        padding-left: 30px;
        color: #797979;
    }

    .phystudent-info {
        width: 80%;
        margin-left: 30px;
        margin-bottom: 10px;
        border-collapse: collapse;
    }

    .phystudent-info tr td {
        min-width: 240px;
        padding-left: 10px;
        border: 1px solid #F7F7F8;
        line-height: 40px;
    }

    .phystudent-info tr td:nth-child(2n+1) {
        min-width: 140px;
        padding-left: 0;
        text-align: center;
        background-color: #F7F7F8;
    }

    .score-content {
        padding-bottom: 20px;
    }

    .stu-physical-mark {
        margin-left: 30px;
        width: 80%;
        min-width: 800px;
        font-size: 0;
    }

    .mark-item {
        display: inline-block;
        box-sizing: border-box;
        width: 50%;
        height: 40px;
        line-height: 40px;
        font-size: 0;
        border-right: 1px solid #F7F7F8;
        border-bottom: 1px solid #F7F7F8;
        overflow: hidden;
    }

    .mark-item:nth-child(1),
    .mark-item:nth-child(2) {
        border-top: 1px solid #F7F7F8;
    }

    .mark-item:nth-child(2n + 1) {
        border-left: 1px solid #F7F7F8;
    }

    .mark-item div {
        display: inline-block;
        font-size: 16px;
    }

    .mark-item .mark-key {
        min-width: 140px;
        box-sizing: content-box;
        text-align: center;
        border-right: 1px solid #F7F7F8;
        background-color: #F7F7F8;
    }

    .mark-value {
        padding-left: 15px;
    }

    .mark-score {
        width: 20%;
        text-align: center;
    }

    .nophysicalScore {
        line-height: 100px;
        text-align: center;
        color: #797979;
    }

    .red {
        color: red;
    }
</style>